package com.egg.ylt.activity;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;

import com.egg.ylt.R;
import com.egg.ylt.Utils.Constants;
import com.egg.ylt.adapter.ADA_UserPhotoListAdapter;
import com.egg.ylt.pojo.UserPhotoListEntity;
import com.egg.ylt.presenter.impl.PhotoBrowserPresenter;
import com.egg.ylt.view.IPhotoBrowserView;
import com.egg.ylt.widget.imagepicker.ImagesDataHolder;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.yonyou.framework.library.base.BaseActivity;
import com.yonyou.framework.library.bean.ErrorBean;
import com.yonyou.framework.library.common.CommonUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created By Dlx
 * on 2019/3/3
 */
public class ACT_PhotoBrowser extends BaseActivity<PhotoBrowserPresenter> implements IPhotoBrowserView, XRecyclerView.LoadingListener {
    @BindView(R.id.recyclerView)
    XRecyclerView recyclerView;
    @BindView(R.id.common_toolbar)
    Toolbar mToolbar;
    private List<UserPhotoListEntity.ListBean> imageUrlList = new ArrayList<>();
    private ADA_UserPhotoListAdapter adapter;
    private int pageSize = 20, pageNum = 1;
    private String itemType;
    private String date;
    private int totalPics = 0;

    @Override
    protected boolean isApplyKitKatTranslucency() {
        return false;
    }

    @Override
    protected void getBundleExtras(Bundle extras) {

    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.act_photobrowser;
    }

    @Override
    protected View getLoadingTargetView() {
        return null;
    }

    @Override
    protected void initViewsAndEvents() {
        itemType = getIntent().getStringExtra(Constants.GROWTH_STAMP_ITEM_TYPE);
        date = getIntent().getStringExtra(Constants.GROWTH_STAMP_DATE);
        setSupportActionBar(mToolbar);
        mToolbar.setTitle(date);
        mPresenter.getUserPhotoList(itemType, date, pageSize, pageNum);
        adapter = new ADA_UserPhotoListAdapter(this, mPresenter);
        recyclerView.setAdapter(adapter);
        recyclerView.setPullRefreshEnabled(false);
        recyclerView.setLoadingListener(this);
        adapter.updateList(imageUrlList);
    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return false;
    }

    @Override
    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        return false;
    }

    @Override
    protected TransitionMode getOverridePendingTransitionMode() {
        return null;
    }

    @Override
    public void showBusinessError(ErrorBean error) {

    }

    @Override
    public void onUserPhotoListSuccess(UserPhotoListEntity result) {
        if (result != null) {
            adapter.updateList(result.getList());
            totalPics = result.getTotalPage();
        }
    }

    @Override
    public void onUserPhotoListFailed(String content) {

    }

    @Override
    public void onLoadMorePhotosSuccess(UserPhotoListEntity more) {
        if (more != null && more.getList().size() != 0) {
            adapter.update(more.getList());
            recyclerView.loadMoreComplete();
            if (more.getList().size() < pageSize) {
                recyclerView.setNoMore(true);
            }
        }
    }

    @Override
    public void onLoadMorePhotosFailed(String content) {

    }

    @Override
    public void showToast(String content) {
        CommonUtils.makeEventToast(this, content, false);
    }

    @Override
    public void onRefresh() {

    }

    @Override
    public void onLoadMore() {

        pageNum++;
        mPresenter.getUserPhotoList(itemType, date, pageSize, pageNum);
    }
}
